package task2_2;

import java.util.List;
import java.util.Collections;
import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: ATroshanin
 * Date: 01.06.2006
 * Time: 17:07:12
 * To change this template use File | Settings | File Templates.
 */
public class Lexem {

    private static final List FUNCTIONS = new ArrayList(); {
    FUNCTIONS.add("sin");
    FUNCTIONS.add("cos");
    FUNCTIONS.add("pow");
    }

    public static final String TYPE_DIGIT  = "digit";
    public static final String TYPE_ZNAK   = "znak";

    public static final String TYPE_TERM        = "term";
    public static final String TYPE_FUNCTION    = "function";
    public static final String TYPE_NUMBER      = "number";
    public static final String TYPE_SYMBOL      = "symbol";

    private String value;
    private String type;
    private double douleValue;

    public Lexem(String value, String type) {
        this.value = value;
        this.type = type;
        if (this.type.equals(TYPE_TERM) && Collections.binarySearch(FUNCTIONS ,value) != -1) {
            this.type = TYPE_FUNCTION;
        }
    }

    public String getValue() {
        return value;
    }

    public String getType() {
        return type;
    }

    public double getDouleValue() {
        return douleValue;
    }

    public void setDouleValue() {
        //if (type.equals(TYPE_DIGIT)) {
        if (type.equals(TYPE_NUMBER)) {
            douleValue = Double.parseDouble(value);
        }
    }

    public void setDouleValue(double doubleValue) {
        douleValue = doubleValue;
    }

    public String toString() {
        return "Lexem: [Type = " + type + "][Value = " + value +"]";
    }

}
